package com.qf.springbootday02starter.conf;

import com.qf.springbootday02starter.utils.QfFileAppender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import java.io.IOException;

@Configuration
@EnableConfigurationProperties({QfProperties.class})
@ConditionalOnProperty(prefix = "qf",name = "filepath")
public class QfAutoConfiguration {
    @Autowired
    QfProperties qfProperties;

    @Bean
    @Scope("prototype")
    public QfFileAppender qfFileAppender() throws IOException {

        final QfFileAppender qfFileAppender = new QfFileAppender(qfProperties.getFilepath());

        return qfFileAppender;

    }
}
